package com.baizhi.controller;

import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("login")
    @ResponseBody
    public Map login(String name, String password, HttpSession session){
        Map map = new HashMap();
        User user = userService.selectByName(name);
        if(user!=null && user.getPassword().equals(password)){
            session.setAttribute("login",user);
            map.put("flag",true);
            map.put("admin",user.getIsadmin());
        }else{
            map.put("flag",false);
        }
        return map;
    }
}
